<template>
    <div >
        <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
                  <van-list v-model="loading"
                    :finished="finished"
                    finished-text="没有更多数据"
                    @load="onload"
                    :immediate-check='false'
                    style="margin-bottom: 50px;">
                    <van-cell v-for="(item,index) in list" :key="index">
                        <div class="titlefont"> {{item.workSettings}}</div>
                        <div class="infosfont"> 思政工作频次类型:{{item.frequency}}</div>
                        <div class="infosfont"> 
                            思政工作时间:{{item.showTime}}</div>
                        <div class="infosfont"> 配置人:{{item.configuration}}</div>
                        <div class="infosfont" style="display: flex;"> 配置时间:{{item.configTime}}</div>
                        <van-button  type="danger" size="mini" @click="deteleSet(index,item)">删除配置</van-button>
                    </van-cell>

                  </van-list>
              </van-pull-refresh>
    </div>
</template>
<script>
import {getszjssetList,deleteSzjsFromDetail} from '@/api/gettodo'
import {mapGetters} from 'vuex'
import { Dialog, Notify } from 'vant'
export default {
    name:'szjssetList',
    data(){
        return{
            list:[],
            refreshing:false,
            loading:false,
            finished:false,
            getListQuery:{source:"MOBILE",page:1,rows:10,size:10},
            maxpage:100,
            isgetlistZero:true,
        }
    },
    computed:{
        ...mapGetters(['user']),
    },
    created(){
       
    },
    activated(){
        console.log('createdcreatedcreated');
        this.refreshing=true;
        this.finished=false;
        this.loading=true;
        this.getListQuery.page=1;
        this.maxpage=100;
        this.isgetlistZero=true;
        this.list=[];
        this.getList();
    },
    methods:{
        getList(){
              console.log('getListgetListgetList');
            if(this.refreshing){
               this.refreshing=false;
            }
            getszjssetList(Object.assign(this.getListQuery,
                {userName:this.user.userName}))
                .then((result)=>{
                    if(!result.data){
                        this.loading=false;
                        Notify(result.message);
                        return;
                    }
                    let addlistdata=this.list;
                    if(this.getListQuery.page==1){  
                        if(result.data.data.content){
                            addlistdata = result.data.data.content
                        }
                        this.maxpage=result.data.data.totalPages;
                    }else {
                        if(result.data.data.content){
                            addlistdata= addlistdata.concat(result.data.data.content) 
                        }
                    }
                    for(let i=0;i<addlistdata.length;i++){
                        if(addlistdata[i].frequencyType=='周'){
                            addlistdata[i].showTime=addlistdata[i].startTime+"至"+
                               addlistdata[i].endTime;
                        }else if(addlistdata[i].frequencyType=='月度'){
                            addlistdata[i].showTime=addlistdata[i].year+"年"+
                               addlistdata[i].month+"月";
                        }else if(addlistdata[i].frequencyType=='季度'){
                            addlistdata[i].showTime=addlistdata[i].year+"年"+
                               addlistdata[i].quarterly;
                        }else if(addlistdata[i].frequencyType=='年度'){
                            addlistdata[i].showTime=addlistdata[i].year+"年";
                        }
                    }
                    this.loading = false;
                    this.list=addlistdata;
                });
        },
        onload(){
              console.log('onloadonloadonloadonload');
            // if(!this.isgetlistZero){
                if(this.getListQuery.page<this.maxpage){
                    this.getListQuery.page = this.getListQuery.page+1;
                    this.loading=true;
                    this.getList();
                }else{
                    this.finished=true;
                    this.loading = false;
                }
            // }else{
            //       this.loading = false;
            //       this.isgetlistZero=false;
            // }
          
        },
        onRefresh(){
             console.log('onRefreshonRefreshonRefresh');
            this.finished=false;
            this.refreshing=true;
            this.isgetlistZero=true;
            this.loading=false;
            this.getListQuery.page=1;
            this.maxpage=100;
            this.list=[];
            this.getList();
        },deteleSet(index,item){
            Dialog.confirm({
                title:'提示',
                message:'请确认是否删除该思政纪实工作配置，删除后不可恢复！'
            })
            .then(()=>{  //确认删除
                console.log("确认删除")
                deleteSzjsFromDetail(Object.assign({id:item.id},{userName:this.user.userName}))
                    .then((res)=>{
                        if(res.data.errcode==0){
                            this.onRefresh();
                        }else{
                            Notify(res.message)
                        }
                    })
            })
            .catch(()=>{ //取消
                
            })

            
           
        },
    }
}
</script>
<style scoped>
.btn{
     margin-bottom: 60px;
     margin-top: 60px;
 }

</style>